<?php
use yii\helpers\Url;
use yii\widgets\LinkPager;

?>

<style>
	#service-log td .logBtn {
		display: inline-block;
		width: 48px;
		height: 45px;
		background: #faa552 url("<?= Yii::getAlias('@web/backend/img/service/record_ico.png') ?>") 50% 50% no-repeat;
		vertical-align: middle;
		border-radius: 5px;
	}
	.form-inline{width: auto;}
	.form-inline input[type="text"]{height: 40px;line-height: 40px;vertical-align: middle;}
	.btnMd{width: 100px; color: #fff;border-radius: 6px; height: 40px;line-height: 40px;vertical-align: top;}
	.btnMd input[type="submit"]{display: block; width: 100%; background: 0;border:0;font-size: 17px;vertical-align: middle}
	@media (min-width: 992px) and (max-width: 1440px){
		#service-log td .service-log-type{
			position: relative;
			display: flex;
			justify-content: center;
			align-items: center;
			height: inherit;
		}
	}
</style>

<?= $this->render('header'); ?>

<div id="service-log" class="container">
<div class="mg20-y">
	<form class="form-inline" action="">
		<div class="form-group">
			<label class="mr20" for="">会员</label>
			<input type="text" name="member">
		</div>

		<div class="form-group mr20">
			<label class="mg20-x" for="">员工</label>
			<input type="text" name="employee">
		</div>

		<div class="form-group">
			<div class="btnMd">
				<input class="" type="submit" value="搜索">
			</div>
		</div>
	</form>
</div>

	<div class="table-responsive">
		<?php if(empty($list)){?>
		<table class="table table-bordered">
			<thead>
			<tr>
				<th>会员</th>
				<th>美容师-服务项目</th>
				<th>服务日期</th>
				<th>服务时间</th>
				<th>员工</th>
				<th>提成</th>
				<th>预约时间</th>
				<th>房间</th>
				<th>服务记录</th>
			</tr>
			</thead>
			<tbody>
			<tr>
				<td colspan="7" align="center"><img src="<?=Yii::getAlias('@web/backend/img/nodata.gif');?>"></td>
			</tr>
			</tbody>
		</table>
		<?php }else{?>
		<table class="table table-bordered">
			<thead>
			<tr>
				<th>会员</th>
				<th>美容师-服务项目</th>
				<th>服务日期</th>
				<th>服务时间</th>
				<th>员工</th>
				<th>提成</th>
				<th>预约时间</th>
				<th>房间</th>
				<th>服务记录</th>
			</tr>
			</thead>
			<tbody>

			<?php foreach($list as $service): ?>
			<tr>
				<td><img class="person role" aid="<?= $service['s_id']?>" alt="头像"><?= $service['service_member_name'] ?></td>
				<td><div class="service-log-type clearfix">

						<span><?= $service['employee_name'] ?>-<?= $service['beautycartd_name'] ?></span>
					</div></td>
				<?php $dateTime = explode(' ', $service['service_addtime']) ?>
				<td><?= $dateTime[0] ?></td>
				<td><?= substr($dateTime[1], 0, 5) . '-' . substr($service['service_endtime'], 11, 5) ?></td>

				<td><?= $service['employee_name'] ?></td>
				<td ondblclick="changeText(this, <?= $service['extend_id'] ?>, <?= $service['reward'] ?>, <?= $service['employee_id'] ?>)"><?= $service['reward'] ?></td>

				<td><?= preg_match('/^0/', $service['make_time']) ? '' : $service['make_time'] ?></td>
				<td><?= $service['room_name'] ?></td>
				<td><a class="logBtn remark" durl="<?=Url::to(['remark', 'id' => $service['s_id'], 'u' => 'record'])?>" href="javascript:;"></a></td>
			</tr>
			<?php endforeach; ?>

			</tbody>
		</table>
		<?php }?>
	</div>
	<div class="page">
		<?= LinkPager::widget([
			'pagination' => $page,
//			 'hideOnSinglePage' => true
		]); ?>
	</div>

</div>

<script>
<?php $this->beginBlock('js_index') ?>

	// 文本编程输入框
	function changeText(obj, extend_id, reward, employee_id)
	{
		$(obj).html('<input class="text_repertory pl10 extend_'+ extend_id +'" type="text" reward="'+ reward +'" value="'+ reward +'" onblur="changeReward(this, '+ extend_id +', '+  employee_id+')">');
//		$('.extend_'+extend_id).focus();
	}
	// 修改提成
	function changeReward(obj, extend_id, employee_id)
	{
		obj = $(obj);
		var reward = obj.val();
		$.post('<?= Url::to(['changereward']) ?>', {extend_id:extend_id, reward:reward, employee_id:employee_id}, function(data){
			if (data.status == 1) {
				// 成功
				obj.parent().html(reward);
			} else {
				// 失败
				obj.parent().html(obj.attr('reward'));
			}
		}, 'json');
	}

$(function(){
	$('.role').each(function () {
		var $id =$(this).attr('aid');
		$(this).attr('src','/backend/img/member/ico'+($id%20+1)+'.png');
	});
	function openPage() {
		var obj = $(this);
		var url = obj.attr('durl');
		layer.open({
			type: 2,
			title: '',
			shadeClose: false,
			shade: 0.8,
			maxmin: true, //开启最大化最小化按钮
			area: ['40%', '410px'],
			content: url
		});
	}
	$('.remark').on('click', openPage);
})

<?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_index'], $this::POS_END); ?>
